package com.itheima.mall.web.pms;

import com.itheima.mall.commons.result.Result;
import com.itheima.mall.dubbo.api.pms.PmsSkuStockService;
import com.itheima.mall.entity.domain.pms.SkuStock;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sku")
public class PmsSkuStockController {
    @DubboReference
    private PmsSkuStockService skuStockService;
    //批量更新sku库存信息
    @PostMapping("update/{pid}")
    public Result update(@RequestParam Long pid, @RequestBody SkuStock skuStock){
        skuStock.setId(pid);
        skuStockService.updateById(skuStock);
        return Result.success("修改成功");
    }
    //根据商品ID及sku编码模糊搜索sku库存
    @GetMapping("/{pid}")
    public Result getById(@PathVariable Integer pid,String keyword){
       List<SkuStock> skuStocks = skuStockService.getList(pid,keyword);
       return Result.success(skuStocks);
    }
}
